/**
 * @file MutexLock.hh
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-08
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "Noncopyable.hh"
#include <pthread.h>

namespace snow
{

class MutexLock
    : Noncopyable // 禁止复制，不加引用报错
{
public:
    MutexLock();
    ~MutexLock();

    void lock();
    void unlock();

    pthread_mutex_t *getMutexPtr();

private:
    pthread_mutex_t mutex_;
};

class MutexLockGuard
{
public:
    MutexLockGuard(MutexLock &mutex);
    ~MutexLockGuard();

private:
    MutexLock &mutex_; // 引用，同一把锁
};

} // namespace snow